# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/3 16:50
# @Author   : 郑鲁明
# @Site     : http://www.hzdledu.cn/
# @File     : change_personnel_list.py
# @Software : PyCharm

from selenium.webdriver.support.wait import WebDriverWait  # 等待类
from selenium.webdriver.support import expected_conditions  # 等待条件
from selenium.webdriver.common.by import By  # 定位符
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select


class ChangePersonnelList():
    def __init__(self, driver):
        # 导航栏—招聘管理
        self.rec_management = (By.XPATH, '//*[@id="root"]/section/aside/div/ul/li[1]/div')
        # 导航栏中—变更人事专员列表按钮
        self.changepersonnellist = (By.XPATH, '//*[@id="sale$Menu"]/li[4]/a')
        # 查询按钮
        self.query_open_button = (By.XPATH, '//*[@id="root"]/section/section/main/div/div[1]/button')
        # 下拉框
        self.select_list_button = (By.XPATH, '//*[@id="root"]/section/section/main/div/div[1]/div/div[1]')



        # 查询条件界面右上角的关闭按钮
        self.query_close_button = (By.XPATH, '//*[@class="ant-modal-close-x"]')
        # 查询条件界面的查询按钮
        self.query_button = (By.XPATH, '/html/body/div[2]/div/div[2]/div/div[2]/div[3]/button')
        # 查询条件界面姓名输入框
        self.name_query = (By.ID, 'name')
        # 查询条件界面电话输入框
        self.phone_query = (By.ID, 'phone')
        # 查询条件界面操作人姓名
        self.operator_query = (By.ID, 'operator')


        self.driver = driver
        self.wait = WebDriverWait(driver, 30)

        # 测试时去除
        # self.driver = webdriver.Chrome()

    # 切换至变更人事专员列表页面
    def jump_to(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.rec_management))
            self.driver.find_element(*self.rec_management).click()
            time.sleep(1)
            self.wait.until(expected_conditions.presence_of_element_located(self.changepersonnellist))
            self.driver.find_element(*self.changepersonnellist).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/切换至变更人事专员列表页面错误.png')
            raise e

    # 打开查询界面
    def query_open(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_open_button))
            self.driver.find_element(*self.query_open_button).click()
            time.sleep(1)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/打开查询页面错误.png')
            raise e

    # 关闭查询界面
    def query_close(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_close_button))
            self.driver.find_element(*self.query_close_button).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/关闭查询界面错误.png')
            raise e

    # 查询功能的使用
    def query_function(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_button))
            self.driver.find_element(*self.query_button).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询界面查询错误.png')
            raise e

    # 下拉框的选择
    def drop_down_select(self,select):
        drop_select = (By.XPATH,f'//li[text()="{select}"]')
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.select_list_button))
            self.driver.find_element(*self.select_list_button).click()
            time.sleep(0.5)
            self.wait.until(expected_conditions.presence_of_element_located(drop_select))
            self.driver.find_element(*drop_select).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/下选框选择错误.png')
            raise e

    # 查询条件界面输入姓名
    def query_input_name(self, name):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.name_query))
            self.driver.find_element(*self.name_query).send_keys(name)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/输入姓名错误.png')
            raise e

    # 查询条件界面输入电话
    def query_input_phone(self, phone):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.phone_query))
            self.driver.find_element(*self.phone_query).send_keys(phone)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/输入电话错误.png')
            raise e

    # 查询条件界面输入操作人姓名
    def query_input_operator(self, operator):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.operator_query))
            self.driver.find_element(*self.operator_query).send_keys(operator)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/输入操作人姓名错误')
            raise e
